from django.contrib.sites.models import Site
from django.contrib.syndication.feeds import Feed
from django.utils.feedgenerator import Atom1Feed
from django.conf import settings

from models import News

class RecentNewsRSS(Feed):
    title = "%s news" % Site.objects.get_current()
    link = "/news/"
    description = "Recent news on %s" % Site.objects.get_current()
    description_template = 'news/feed_description.html'    
    item_categories = ("python", "pygame", "open source", "game", "SDL")

    def items(self):
        x = settings.RECENT_NEWS_FEED_OBJECTS
        return News.active_objects.count() > x and News.active_objects.all()[:x] or News.active_objects.all()

                                       
    def item_author_name(self, item):
        return item.creator.get_profile().display_name
    
    def item_author_link(self, item):
        return "/profiles/%s/" % item.creator.username
    
    def item_pubdate(self, item):
        return item.created


class RecentNewsAtom(RecentNewsRSS):
    feed_type = Atom1Feed
    subtitle = RecentNewsRSS.description

